<?php
class Zendvn_View_Helper_AdminTable extends Zend_View_Helper_Abstract{
	public $_component;
	public $_headTitle;
	public function getConfig(){
		$fileConfig = dirname($this->_component['path']).DS.'configs'.DS.$this->_component['control'].DS.$this->_component['activity'].'.ini';
		$configsObj = new Zendvn_Config($fileConfig);
		$configs   	= $configsObj->getConfig("adminListColums");
		array_shift($configs);
		$this->_headTitle =$configs;
	}
    public function adminTable($name = null,$value = null,$attribs = array('class'=>"adminlist"),$options = null ){
    	$this->_component = $options['component'];
    	$this->getConfig();
    	$view = $this->view;
    	$strAttr ="";
    	if($attribs != null) foreach ($attribs as $atrr => $val){
    		$strAttr .= ' '.$atrr.'="'.$val.'" ';
    	}
    	foreach ($this->_headTitle as $key => $val){
    		$strTitle .= $view->adminTableTitle($key,null,null,$val);
    	}
    	$strThead = '<thead>
						<th width="1%">
					<input type="checkbox" name="checkall-toggle" value="" title="Check All" onclick="checkedAll();">
				</th>'.$strTitle.'</tr>
					</thead>';
    	
		 
		if(count($value) >0)foreach ($value as $item){
			$i =0;
			foreach ($this->_headTitle as $key => $val){
				$tmp = $item[$key];
				$val['data'] = $tmp;
				$item[$key] = $val;
			}
			$contentRow .= '<tr class="row'.$i.'">'.$view->adminTableBody(null,$item,null,null).'<tr>';
			$i++;
		}  	
		$strTbody = '<tbody>
		'.$contentRow.'
		</tbody>';
		$colSpan = count($this->_headTitle) +1;
    	$tFoot ='
				<tfoot>
					<tr>
						<td colspan="'.$colSpan.'">
							<div class="container">
								<div class="pagination">
		
									<div class="limit">
										Display #<select id="limit" name="limit" class="inputbox"
											size="1" onchange="Joomla.submitform();">
											<option value="5">5</option>
											<option value="10">10</option>
											<option value="15">15</option>
											<option value="20" selected="selected">20</option>
											<option value="25">25</option>
											<option value="30">30</option>
											<option value="50">50</option>
											<option value="100">100</option>
											<option value="0">All</option>
										</select>
									</div>
									'.$view->paginationControl($view->panigator,'Sliding','AdminPaginator.php',array('component'=>$this->_component)).'
									<input type="hidden" name="limitstart" value="0">
								</div>
							</div>
						</td>
					</tr>
				</tfoot>
				'; 
    	$xhtml ="<table ".$strAttr.">".$strThead.$strTbody.$tFoot."</table>";
    	return $xhtml;
    }
}